<?php
General::getTpl()->assign('extraTitle',"Badwords");

if(!Admin::checkPermission('canManageBadwords')) {
	General::ouputMessage('Fehler','Sie haben nicht gen&uuml;gend Rechte um diese Seite zu betrachten');
}else{
	require_once 'kernel/badwords.php';
	
	if(isset($_GET['do']) && $_GET['do'] == "new") {
		// New BBCode?
		require_once 'kernel/form.php';
		
		// Form-Data
		$formField = array();
		$formField[0]['fieldName'] = "Eingabe";
		$formField[0]['fieldType'] = Form::$TYPE_TEXT;
		$formField[0]['fieldDefaultValue'] = "";
		$formField[0]['fieldCheck'] = true;
		$formField[0]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
		
		$formField[1]['fieldName'] = "Ersetzen";
		$formField[1]['fieldType'] = Form::$TYPE_TEXT;
		$formField[1]['fieldDefaultValue'] = "";
		$formField[1]['fieldCheck'] = true;
		$formField[1]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
		
		$form = new Form();
		$form->initByData("Badword erstellen",true,"Speichern!",$formField);
		
		// Done?
		if($form->completeCheck()) {
			// Create BBCode
			Badwords::getInstance()->addBadword($_POST['Eingabe'],$_POST['Ersetzen']);
			
			General::ouputMessage('Erfolgreich','Das Badword wurde erfolgreich gespeichert.','form');
			
		}else{
			$form->outputFormular('form','formular.html');
		}
	}
	
	if(isset($_GET['do']) && $_GET['do'] == "edit" && isset($_GET['id']) && is_numeric($_GET['id'])) {
		// Get Data
		$data = Badwords::getInstance()->getBadword($_GET['id']);
		// Edit BBCode?
		require_once 'kernel/form.php';
		
		// Form-Data
		$formField = array();
		$formField[0]['fieldName'] = "Eingabe";
		$formField[0]['fieldType'] = Form::$TYPE_TEXT;
		$formField[0]['fieldDefaultValue'] = $data['badInput'];
		$formField[0]['fieldCheck'] = true;
		$formField[0]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
		
		$formField[1]['fieldName'] = "Ersetzen";
		$formField[1]['fieldType'] = Form::$TYPE_TEXT;
		$formField[1]['fieldDefaultValue'] = $data['badReplace'];
		$formField[1]['fieldCheck'] = true;
		$formField[1]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
		
		$form = new Form();
		$form->initByData("Badword bearbeiten",true,"Speichern!",$formField);
		
		// Done?
		if($form->completeCheck()) {
			// Create BBCode
			Badwords::getInstance()->editBadword($_GET['id'],$_POST['Eingabe'],$_POST['Ersetzen']);
			
			General::ouputMessage('Erfolgreich','Das Badword wurde erfolgreich gespeichert.','form');
			
		}else{
			$form->outputFormular('form','formular.html');
		}
	}
	

	
	if(isset($_GET['do']) && $_GET['do'] == "del" && isset($_GET['id']) && is_numeric($_GET['id'])) {
		require_once './kernel/formCheck.php';
		$form = new FormCheck("Bist du sicher?","L&ouml;schen");
		// Done?
		if($form->completeCheck()) {
			if($form->isChecked()) {
				// Delete navigation
				Badwords::getInstance()->deleteBadword($_GET['id']);
			}
		}else{
			$form->outputFormular('form','formular.html');
		}
	}
	
	
	
	
	$badwords = Badwords::getBadwords();
	
	General::getTpl()->assign('badwords',$badwords);
	
	General::getTpl()->assign('body',
		General::getTpl()->fetch('../admin/badwords.html'));
}
?>